<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>登录</title>
  <script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
  <script th:src="@{/js/md5.min.js}"></script>
  <script th:src="@{/js/common.js}"></script>
</head>
<body>
<form method="post">
  <h3>用户登录</h3>
  <div>
    <input type="text" id="mobile" name="mobile" placeholder="手机号码" required>
  </div>
  <div>
    <input type="password" id="password" name="password" placeholder="密码" required>
  </div>
  <div>
    <button type="reset" onclick="reset()">重置</button>
    <button type="button" onclick="login()">登录</button>
  </div>
</form>
<script>
  function login() {
    const pass = $("#password").val();
    const password = g_mix_password(pass)

    axios.post("/login", {
      mobile: $("#mobile").val(),
      password: password
    }).then(resp => {
      const redirect = resp.headers["s_redirect_uri"];
      window.location.href = redirect || "/goods.html";
    }).catch(error => {
      console.log({error});
      alert(error.response.data);
    });

    /*$.ajax({
      url: '/login',
      type: 'POST',
      data: {
        mobile: $("#mobile").val(),
        password: password
      },
      success(data, status, xhs) {
        console.log(xhs)
        console.log(xhs.getResponseHeader("S_REDIRECT_URI"))
        const redirect = xhs.getResponseHeader("S_REDIRECT_URI");
        if (data === true) {
          // window.location.href = redirect || "/goods/page";
        }
      },
      error() {
      }
    });*/
  }
</script>
</body>
</html>
